import request from '@/utils/request'

// API响应接口
export interface ApiResponse<T> {
  code: number
  msg: string
  data: T
}

// 接口定义
export interface HanziGenerationRequest {
  char: string
  steps: number
}

export interface HanziGenerationResponse {
  id: number
  chineseChar: string
  steps: number
  status: 'processing' | 'success' | 'failed'
  ossUrl: string | null
  generationTime: number | null
  errorMessage: string | null
  requestId: string | null
  createTime: string
  updateTime: string
}

export interface StatsResponse {
  totalRecords: number
  successRecords: number
  failedRecords: number
  processingRecords: number
  successRate: string
}

// 分页响应接口
export interface PageResponse<T> {
  list: T[];
  total: number;
  size: number;
  current: number;
  pages: number;
}

// 汉字查询响应接口
export interface CharSearchResponse {
  list: HanziGenerationResponse[];
  total: number;
}

/**
 * 生成汉字
 * @param data 请求参数
 * @returns 返回请求结果
 */
export function generateHanzi(data: HanziGenerationRequest) {
  return request({
    url: '/api/hanzi/generate',
    method: 'post',
    data
  }) as Promise<ApiResponse<HanziGenerationResponse>>
}

/**
 * 根据汉字查询记录
 * @param chineseChar 汉字字符
 * @returns 返回请求结果
 */
export function getRecordsByChar(chineseChar: string) {
  return request({
    url: `/api/hanzi/char/${chineseChar}`,
    method: 'get'
  }) as Promise<ApiResponse<PageResponse<HanziGenerationResponse>>>
}

/**
 * 分页查询生成记录
 * @param page 页码
 * @param size 每页大小
 * @returns 返回请求结果
 */
export function getRecordsByPage(page: number, size: number) {
  return request({
    url: '/api/hanzi/page',
    method: 'get',
    params: { page, size }
  }) as Promise<ApiResponse<PageResponse<HanziGenerationResponse>>>
}

/**
 * 获取汉字生成统计信息
 * @returns 返回请求结果
 */
export function getHanziStats() {
  return request({
    url: '/api/hanzi/stats',
    method: 'get'
  }) as Promise<ApiResponse<StatsResponse>>
} 